package fr.inserm.u915.organifooyi.model;


import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;


@Entity(name="prelevement")
@Table(name="prelevement")
@NamedQueries({
	    @NamedQuery(name="prelevementsListAll",
	                query="select p from prelevement as p ORDER BY p.integralis,p.cdNumber"),
	    @NamedQuery(name="prelevementsFindByName",
	                query="select p from prelevement as p where (p.integralis= :term or p.cdNumber= :term)")

	})
public class Prelevement extends AbstractUpdatableObject
	{	
	
	@Column(name="integralis",length=50)
	private String integralis;
	@Column(name="cd_number",length=50)
	private String cdNumber;


	
	@OneToMany(fetch = FetchType.LAZY,mappedBy="prelevement")
	@JoinTable(name="extraction",joinColumns={
			@JoinColumn(name="prelevement_id")
		})
	private List<Extraction> extractions=new ArrayList<Extraction>();
	
	
	public List<Extraction> getExtractions()
		{
		return extractions;
		}
	
	public void setExtractions(List<Extraction> extractions) {
		this.extractions = extractions;
		}
	
	
	public String getIntegralis() {
		return integralis;
		}
	
	public void setIntegralis(String integralis)
		{
		this.integralis = (integralis==null?null:integralis.trim().toUpperCase());
		}
	
	public String getCdNumber()
		{
		return cdNumber;
		}
	
	public void setCdNumber(String cdNumber)
		{
		this.cdNumber = (cdNumber==null?null:cdNumber.trim().toUpperCase());
		}


			
	@Transient
	public String getLabel()
		{
		if(integralis!=null) return integralis;
		if(cdNumber!=null) return cdNumber;
		if(getId()!=null) return "ID."+getId();
		return "undefined";
		}
	
	@Override
	public String toString() {
		return "("+getId()+") INTEGRALIS:"+integralis+" CD:"+cdNumber;
		}
	}
